n = input()
mx = 0
for i in range(len(n)):
    for j in range(i, len(n)):
        x = int(n[i:j+1])
        k = 0
        for d in range(1,x+1):
            if x%d == 0:
                k += 1
        if k == 2:
            mx = max(mx,x)
print (mx)
